package com.ruoyi.project.paea.paeaLostVoucher.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.security.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.paea.paeaLostVoucher.domain.PaeaLostVoucher;
import com.ruoyi.project.paea.paeaLostVoucher.service.IPaeaLostVoucherService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import java.util.Arrays;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 缺票登记信息Controller
 *
 * @author ruoyi
 * @date 2020-04-13
 */
@Controller
@RequestMapping("/paea/paeaLostVoucher")
public class PaeaLostVoucherController extends BaseController
{
    private String prefix = "paea/paeaLostVoucher";

    @Autowired
    private IPaeaLostVoucherService paeaLostVoucherService;

    @RequiresPermissions("paea:paeaLostVoucher:view")
    @GetMapping()
    public String paeaLostVoucher()
    {
        return prefix + "/paeaLostVoucher";
    }

    /**
     * 查询缺票登记信息列表
     */
    @RequiresPermissions("paea:paeaLostVoucher:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaLostVoucher paeaLostVoucher)
    {
        startPage();
        List<PaeaLostVoucher> list = paeaLostVoucherService.list(new QueryWrapper<>(paeaLostVoucher));
        return getDataTable(list);
    }

    /**
     * 导出缺票登记信息列表
     */
    @RequiresPermissions("paea:paeaLostVoucher:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaLostVoucher paeaLostVoucher)
    {
        List<PaeaLostVoucher> list = paeaLostVoucherService.list(new QueryWrapper<>(paeaLostVoucher));
        ExcelUtil<PaeaLostVoucher> util = new ExcelUtil<PaeaLostVoucher>(PaeaLostVoucher.class);
        return util.exportExcel(list, "paeaLostVoucher");
    }

    /**
     * 新增缺票登记信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存缺票登记信息
     */
    @RequiresPermissions("paea:paeaLostVoucher:add")
    @Log(title = "缺票登记信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaLostVoucher paeaLostVoucher)
    {
        return toAjax(paeaLostVoucherService.insertPaeaLostVoucher(paeaLostVoucher));
    }

    /**
     * 修改缺票登记信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PaeaLostVoucher paeaLostVoucher = paeaLostVoucherService.getById(id);
        mmap.put("paeaLostVoucher", paeaLostVoucher);
        return prefix + "/edit";
    }

    /**
     * 修改保存缺票登记信息
     */
    @RequiresPermissions("paea:paeaLostVoucher:edit")
    @Log(title = "缺票登记信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PaeaLostVoucher paeaLostVoucher)
    {
        return toAjax(paeaLostVoucherService.updatePaeaLostVoucher(paeaLostVoucher));
    }


    /**
     * 删除缺票登记信息
     */
    @RequiresPermissions("paea:paeaLostVoucher:remove")
    @Log(title = "缺票登记信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(paeaLostVoucherService.removeByIds(Arrays.asList(ids.split(","))));
    }
    /**
     * 删除缺票登记信息
     */
    @RequiresPermissions("paea:paeaLostVoucher:centerConfirm")
    @Log(title = "中心确认缺票登记信息", businessType = BusinessType.UPDATE)
    @PostMapping( "/centerConfirm")
    @ResponseBody
    public AjaxResult centerConfirm(String ids)
    {
        List<String> list = Arrays.asList(ids.split(","));
        return toAjax(paeaLostVoucherService.saveCenterConfirm(list));
    }
    /**
     * 删除缺票登记信息
     */
    @RequiresPermissions("paea:paeaLostVoucher:cancel")
    @Log(title = "中心确认缺票登记信息", businessType = BusinessType.UPDATE)
    @PostMapping( "/cancel")
    @ResponseBody
    public AjaxResult cancel(String ids)
    {
        List<String> list = Arrays.asList(ids.split(","));
        return toAjax(paeaLostVoucherService.cancel(list));
    }
}
